/*
 * Nazwa robocza: ScreenShooter
 * Wersja: 0.1
 * Z dnia: 2012-06-20
 *
 * Opis programu:
 *          Aplikacja typu klient-serwer oparta na protokole TCP/IP,
 *          umozliwiajaca podglad ekranu komputera-serwera oraz
 *          proste operacje przeprowadzane za pomoca myszki oraz klawiatury
 *
 * Autorzy:
 *          Wojciech Gołuchowski
 *          Daniel Czyczyn-Egird
 *
 * KLASA: OpcjeKlienta - okno konfiguracji klienta
 */
package pl.screenshooter.gui;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.GroupLayout;
import javax.swing.JSpinner;
import javax.swing.JLabel;
import javax.swing.SpinnerNumberModel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import pl.screenshooter.server.Config;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class OpcjeKlienta extends javax.swing.JFrame {
	
	private Config config = new Config();
	private int port = 1235;
	private String host = "127.0.0.1";

    /** Creates new form OpcjeSerwera */
    public OpcjeKlienta() {
        initComponents();
    }
    
    public Config getConfig() {
    	return config;
    }
    
    public String getHost() {
    	return host;
    }
    
    public int getPort() {
    	return port;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton1.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent e) {
        		config.imgHeight = (Integer)heightSpinner.getValue();
        		config.imgWidth = (Integer)widthSpinner.getValue();
        		config.period = (Integer)freqSpinner.getValue();
        		config.quality = ((Integer)jpgCompressionSpinner.getValue())/10.0f;
        		
        		host = hostTextField.getText();
        		port = (Integer)portSpinner.getValue();
        		
        		setVisible(false);
        	}
        });

        setTitle("Opcje klienta");
        setResizable(false);

        jLabel1.setText("Port");

        jLabel2.setText("Adres serwera");

        jButton1.setText("Zastosuj");
        
        JLabel lblStopieKompresji = new JLabel("Jakość obrazu (0-10)");
        
        lblNewLabel = new JLabel("Częstotliwość [ms]");
        
        lblNewLabel_1 = new JLabel("Szerokość obrazu [px]");
        
        lblNewLabel_2 = new JLabel("Wysokość obrazu [px]");
        
        portSpinner = new JSpinner();
        portSpinner.setModel(new SpinnerNumberModel(1235, 1, 65535, 1));
        
        hostTextField = new JTextField();
        hostTextField.setHorizontalAlignment(SwingConstants.LEFT);
        hostTextField.setText("127.0.0.1");
        
        jpgCompressionSpinner = new JSpinner();
        jpgCompressionSpinner.setModel(new SpinnerNumberModel(5, 0, 10, 1));
        
        freqSpinner = new JSpinner();
        freqSpinner.setModel(new SpinnerNumberModel(new Integer(1000), new Integer(0), null, new Integer(10)));
        
        widthSpinner = new JSpinner();
        widthSpinner.setModel(new SpinnerNumberModel(new Integer(800), new Integer(1), null, new Integer(10)));
        
        heightSpinner = new JSpinner();
        heightSpinner.setModel(new SpinnerNumberModel(new Integer(600), new Integer(1), null, new Integer(10)));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        layout.setHorizontalGroup(
        	layout.createParallelGroup(Alignment.LEADING)
        		.addGroup(layout.createSequentialGroup()
        			.addContainerGap()
        			.addGroup(layout.createParallelGroup(Alignment.LEADING)
        				.addGroup(layout.createSequentialGroup()
        					.addComponent(jLabel1)
        					.addPreferredGap(ComponentPlacement.RELATED, 117, Short.MAX_VALUE)
        					.addComponent(portSpinner, GroupLayout.PREFERRED_SIZE, 146, GroupLayout.PREFERRED_SIZE))
        				.addGroup(layout.createSequentialGroup()
        					.addComponent(jLabel2)
        					.addPreferredGap(ComponentPlacement.RELATED, 66, Short.MAX_VALUE)
        					.addComponent(hostTextField, GroupLayout.PREFERRED_SIZE, 146, GroupLayout.PREFERRED_SIZE))
        				.addGroup(layout.createSequentialGroup()
        					.addComponent(lblStopieKompresji)
        					.addPreferredGap(ComponentPlacement.RELATED, 44, Short.MAX_VALUE)
        					.addComponent(jpgCompressionSpinner, GroupLayout.PREFERRED_SIZE, 146, GroupLayout.PREFERRED_SIZE))
        				.addGroup(layout.createSequentialGroup()
        					.addComponent(lblNewLabel)
        					.addPreferredGap(ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
        					.addComponent(freqSpinner, GroupLayout.PREFERRED_SIZE, 146, GroupLayout.PREFERRED_SIZE))
        				.addGroup(layout.createSequentialGroup()
        					.addComponent(lblNewLabel_1)
        					.addPreferredGap(ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
        					.addComponent(widthSpinner, GroupLayout.PREFERRED_SIZE, 146, GroupLayout.PREFERRED_SIZE))
        				.addGroup(layout.createSequentialGroup()
        					.addComponent(lblNewLabel_2)
        					.addPreferredGap(ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
        					.addComponent(heightSpinner, GroupLayout.PREFERRED_SIZE, 146, GroupLayout.PREFERRED_SIZE))
        				.addGroup(layout.createSequentialGroup()
        					.addGap(93)
        					.addComponent(jButton1)))
        			.addContainerGap())
        );
        layout.setVerticalGroup(
        	layout.createParallelGroup(Alignment.LEADING)
        		.addGroup(layout.createSequentialGroup()
        			.addContainerGap()
        			.addGroup(layout.createParallelGroup(Alignment.BASELINE)
        				.addComponent(jLabel1)
        				.addComponent(portSpinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        			.addPreferredGap(ComponentPlacement.RELATED)
        			.addGroup(layout.createParallelGroup(Alignment.BASELINE)
        				.addComponent(jLabel2)
        				.addComponent(hostTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        			.addPreferredGap(ComponentPlacement.UNRELATED)
        			.addGroup(layout.createParallelGroup(Alignment.BASELINE)
        				.addComponent(lblStopieKompresji)
        				.addComponent(jpgCompressionSpinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        			.addPreferredGap(ComponentPlacement.RELATED)
        			.addGroup(layout.createParallelGroup(Alignment.BASELINE)
        				.addComponent(lblNewLabel)
        				.addComponent(freqSpinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        			.addPreferredGap(ComponentPlacement.RELATED)
        			.addGroup(layout.createParallelGroup(Alignment.BASELINE)
        				.addComponent(lblNewLabel_1)
        				.addComponent(widthSpinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        			.addPreferredGap(ComponentPlacement.RELATED)
        			.addGroup(layout.createParallelGroup(Alignment.BASELINE)
        				.addComponent(lblNewLabel_2)
        				.addComponent(heightSpinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        			.addPreferredGap(ComponentPlacement.RELATED)
        			.addComponent(jButton1)
        			.addContainerGap(39, Short.MAX_VALUE))
        );
        getContentPane().setLayout(layout);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-231)/2, (screenSize.height-140)/2, 315, 273);
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new OpcjeSerwera().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private JLabel lblNewLabel;
    private JLabel lblNewLabel_1;
    private JLabel lblNewLabel_2;
    private JSpinner portSpinner;
    private JTextField hostTextField;
    private JSpinner jpgCompressionSpinner;
    private JSpinner freqSpinner;
    private JSpinner widthSpinner;
    private JSpinner heightSpinner;
}
